import util from "@/utils/util";
import axios from "axios";
import config from "@/config";
import { message } from "ant-design-vue";

const service = axios.create({
    baseURL: config.baseUrl,
    timeout: 5000,
    responseType: "json",
    headers: {
        "Content-Type": "application/json;charset=utf-8",
    },
});

const key = "httpmsg";

service.interceptors.response.use(
    response=>{
        if (response.status === 200) {
            return Promise.resolve(response.data);
        } else {
            return Promise.reject(response);
        }
    },
    error => {
        console.error(error);
        if(error.response.status){
            switch (error.response.status) {
                case 404:
                    message.error({
                        content: "网络请求不存在",
                        key: key,
                    });
                    break;
            }
            return Promise.reject(error);
        }
    }
);